//package nancal.mp
//
//import com.offbytwo.jenkins.JenkinsServer
//import integration.TestBase
//import nancal.mp.db.mongo.MobileCodeModuleEnum
//import nancal.mp.db.mongo.SubSystemEnum
//import nancal.mp.db.mongo.entity.admin.AdminUser
//import nancal.mp.db.mongo.entity.sys.SsoConfig
//import nancal.mp.db.mongo.entity.sys.SubSystemInfo
//import nancal.mp.db.mongo.entity.sys.SubSystemUserInfo
//import nancal.mp.db.mongo.entity.sys.UserAuthInfo
//import nancal.mp.db.mongo.extend.getAppDeploySetting
//import nancal.mp.db.mongo.mor
//import nancal.mp.db.redis.rer
//import nancal.mp.mvc.ops.K8sDeploymentController
//import nancal.mp.service.AliSmsService
//import nancal.mp.service.jenkins.JenkinsPipeLineStyleScript
//import nancal.mp.service.jenkins.JenkinsService
//import nbcp.base.comm.JsonMap
//import nbcp.base.db.IdName
//import nbcp.base.enums.JsonSceneScopeEnum
//import nbcp.base.extend.FromJson
//import nbcp.base.extend.ToJson
//import nbcp.base.extend.must
//import nbcp.base.utils.*
//import nbcp.myoql.db.mongo.query
//import nbcp.myoql.db.mongo.queryById
//import org.junit.jupiter.api.Test
//import org.springframework.beans.factory.annotation.Autowired
//import org.springframework.beans.factory.annotation.Value
//import java.net.URI
//
//class jenkins_test : TestBase() {
//
//    @Test
//    fun testJenkinsLog() {
//        var ent = AdminUser();
//        println(ent.ToJson(JsonSceneScopeEnum.WEB))
//    }
//
//    @Test
//    fun testJenkinsPipeline() {
//
//        var jobId = "61d7aa70425cba0d03025a50"
//        var log = mor.dev.jenkinsLog.queryById(jobId).toEntity().must().elseThrow { "" }
//
//        var job = JenkinsPipeLineStyleScript(log);
//
//        println(job.getK8sJenkinsPipeLine())
//    }
//
//    @Test
//    fun testJenkinsbuildJobWithId() {
//        var buildResult = k8sController.deployWithLog("6273c07f85bcf44a68416659")
//        println(buildResult)
//    }
//
//    @Test
//    fun testJenkinsbuildJob() {
//        var deploySetting = mor.dev.appDeploySetting.getAppDeploySetting();
//        var buildResult = jenkinsService.buildPublishJob(
//            deploySetting.jenkinsServer.jenkinsHttpUrl,
//            deploySetting.jenkinsServer.userName,
//            deploySetting.jenkinsServer.password,
//            "62319af3eb7da0106f865ecd"
//        );
//
//        println(buildResult)
//    }
//
//    @Test
//    fun testJenkins() {
//        while (true) {
//            var jobNumberResult =
//                SpringUtil.getBean<JenkinsService>()
//                    .getLog("http://192.168.5.217:8080", "admin", "1234", "yun-corp-vue",0)
//
//            println(jobNumberResult.ToJson())
//
//            Thread.sleep(1000)
//        }
//    }
//
//    @Autowired
//    lateinit var k8sController: K8sDeploymentController;
//
//    @Autowired
//    lateinit var jenkinsService: JenkinsService;
//
//
//    private fun getJenkinsClient(serverHost: String, username: String, password: String): JenkinsServer {
//        if (serverHost.isEmpty()) {
//            throw RuntimeException("serverHost不能为空")
//        }
//        return JenkinsServer(
//            URI(serverHost),
//            username,
//            password
//        )
//    }
//
////    @Test
////    fun ddd() {
////        var jenkinsServer = JenkinsServer()
////        jenkinsServer.code = "dev"
////        jenkinsServer.host = "http://192.168.5.217:8080"
////        jenkinsServer.userName = "admin"
////        jenkinsServer.password = "1234"
////        mor.dev.jenkinsServer.doInsert(jenkinsServer)
////
////    }
////
////    @Test
////    fun sssstestJenkins() {
////        var http1 = HttpInvoke()("http://admin:1234@192.168.5.217:8080/crumbIssuer/api/json")
////        var jc = http1.doGet().FromJson<JsonMap>()!!.get("crumb")!!.toString()
////
////        var http = HttpInvoke()("http://admin:1234@192.168.5.217:8080/job/yun-corp-api-java/description")
//////        http.request.setAuthorization("admin", "1234");
////        //http://192.168.5.217:8080/crumbIssuer/api/json
//////        var d = http.doGet()
//////
//////        println(d)
//////
//////        http.request.contentType = "application/xml"
////
////
////        http.request.headers.put("Jenkins-Crumb", jc)
////
////        var e = http.doPost("ddd");
////
////    }
//
//    @Value("\${app.wx.appId:}")
//    var appId: String = "";
//
//    @Value("\${app.wx.appSecret:}")
//    var appSecret: String = "";
//
//
//    @Value("\${app.wx.mchId:}")
//    var mchId: String = ""
//
//    @Value("\${app.wx.mchSecret:}")
//    var mchSecret: String = ""
//
////    @Test
////    fun  testFund(){
////        val res = WxRefundPayRequestData(appId,mchId,"202002222108295401038",out_refund_no = CodeUtil.getCode(),total_fee = 1,refund_fee = 1,refund_desc = "退款测试").doRefundPay(mchSecret)
////
////        //设置订单状态
////        mor.shop.orderInfo.update()
////                .where { it.orderCode mongoEquals this.out_trade_no }
////                .set { it.status to OrderStatusEnum.Refunded }
////                .set { it.payInfo.remark to "已退款" }
////                .exec()
////        println(res.ToJson())
////    }
////
////    @Test
////    fun testPayPerson(){
////
////        val res = Wx2PayPersonServerRequestData(
////                appId, mchId, amount = 500, openid = "oX8Us5KTN8u1yUIwPbEOkvCpSB6E", partner_trade_no = "202002222108295401038", desc = "test"
////        ).doPayPerson(mchSecret)
////
////        //设置订单状态
////        mor.shop.orderInfo.update()
////                .where { it.orderCode mongoEquals this.out_trade_no }
////                .set { it.status to OrderStatusEnum.Refunded }
////                .set { it.payInfo.remark to "已退款" }
////                .exec()
////        println(res.ToJson())
////    }
//
//    @Test
//    fun testGetHeader() {
//        val serverUrl = "http://localhost:3000/user/login"
//        val http = HttpInvoke()(serverUrl)
//
//        val data = JsonMap()
//
//        data.put("user_name", "kotlin/cy");
//        data.put("password", "!QAZ2wsx")
//
//        http.request.headers.set("lang", "zh-CN");
//        http.request.headers.set("Content-Type", "application/x-www-form-urlencoded")
//
//        //response
//        val responseData = http.doPost(data)
//        println(responseData)
//
//        //获取响应cookie  添加到同cok
//        val responseCk = http.response.headers.get("set-cookie")
//        println(responseCk)
//
////        HttpContext.Current.Response.AppendCookie(responseCk)
//
//    }
//
//    @Test
//    fun testSi() {
//        val i = SubSystemUserInfo()
//
//        //5fbb4399d987b51c27e49dac   管理员
//        //gitea   yudong   1@#4Qwer
//        i.user = IdName(id = "5fbb4399d987b51c27e49dac", name = "管理员")
//
//        val gitea = UserAuthInfo()
//        gitea.systemName = SubSystemEnum.gitea
//        gitea.loginName = "yudong"
//        gitea.password = "1@#4Qwer"
//
//        val sonarqube = UserAuthInfo()
//        sonarqube.systemName = SubSystemEnum.sonarqube
//        sonarqube.loginName = "admin"
//        sonarqube.password = "admin"
//
//        val grafana = UserAuthInfo()
//        grafana.systemName = SubSystemEnum.grafana
//        grafana.loginName = "admin"
//        grafana.password = "admin"
//
//        val confluence = UserAuthInfo()
//        confluence.systemName = SubSystemEnum.confluence
//        confluence.loginName = "admin"
//        confluence.password = "fw101"
//
//        val jenkins = UserAuthInfo()
//        jenkins.systemName = SubSystemEnum.jenkins
//        jenkins.loginName = "admin"
//        jenkins.password = "123456987"
//
//        val list = mutableListOf<UserAuthInfo>(gitea, sonarqube, grafana, confluence, jenkins)
//
//        i.authList = list
//
//        mor.sys.subSystemUserInfo.doInsert(i);
//    }
//
//    @Test
//    fun testgetgit() {
//
//        val a = "gitUser"
//
//        val user = mor.sys.subSystemUserInfo.query()
//            .where { it.user.id mongoEquals "5fbb4399d987b51c27e49dac" }
//            .toEntity()!!
//
//        val giteaInfo = user.authList.filter { it.systemName == SubSystemEnum.gitea }.first()
//
//
//    }
//
//    @Test
//    fun testadds() {
//
//        mor.sys.subSystemInfo.doInsert(SubSystemInfo())
//    }
//
//    @Autowired
//    lateinit var smsService: AliSmsService
//
//    @Test
//    fun testsms() {
//        val sendSms =
//            smsService.sendSmsCode("", MobileCodeModuleEnum.Registe, "18500681612", MyUtil.getRandomWithLength(4))
//
//        /* if (sendSms.isNotEmpty()) {
//             return JsonResult.error(sendSms)
//         }
//
//         return JsonResult()*/
//
//    }
//
//    @Test
//    fun initsso() {
//        val sso = SsoConfig()
//
//        sso.name = "数据湖应用"
//        sso.homepageUrl = "http://www.baidu.com"
////        sso.redirectUrl = "http://localhost:8003/open/test"
//        sso.remark = "数据湖的应用配置"
//        sso.corp = IdName("5fe971aeb42c7674bbb6777b", "admin")
//
//        mor.sys.ssoConfig.doInsert(sso)
//
//
//    }
//
//    @Test
//    fun ter() {
//        println(CodeUtil.getCode())    //  5apfn3uac1ds
//        println(MyUtil.getRandomWithLength(24))  //     807629909211389117422780
//        println(Md5Util.getBase64Md5("600f947cf5623024817ebcac:449429723192889905320577"))   //WK0cD4Tql66MkY6wVpNQTQpc
//    }
//
//    @Test
//    fun testredis() {
//
//        val sso = SsoConfig()
//
//        sso.name = "数据湖应用"
//        sso.homepageUrl = "http://www.baidu.com"
////        sso.redirectUrl = "http://localhost:8003/open/test"
//
//        //1min 的 ttl
//        rer.sys.tempToken(CodeUtil.getCode()).set( sso.ToJson())
//    }
//
//
//    @Test
//    fun getNacosConfig() {
//
//        val dataId = "admin-api.yml"
//        val group = "DEFAULT_GROUP"
//        val ns = "kotlin/cy"
//
//        val http = HttpInvoke()("http://192.168.5.213:8848/nacos/v1/cs/configs?dataId=${dataId}&group=${group}&tenant=$ns")
//        val res = http.doGet();
//
//        println(res)
//    }
//
//    @Test
//    fun setNacosConfig() {
//
//        val dataId = "admin-api.yml"
//        val group = "DEFAULT_GROUP"
//        val ns = "kotlin/cy"
//        val type = "yaml"
//        val content = """logging:
//  a: xxx
//  config: classpath:logback-spring.xml
//  file:
//    path: logs
//  level:
//    root: WARN
//
//app:
//  user-system: admin
//  filter:
//    allowOrigins: dev8.cn
//    ignore-log-urls: /open/log,/log,/favicon.ico,/index.html,/webjars/,/swagger-resources/,/v2/api-docs,/swagger-ui.html
//  upload:
//    uploadPath: /opt/upload
//  order:
//    cancelTime: 15
//    receiveTime: 21600
//  wx:
//    appId: wxd5f2957442fc2d0b
//    appSecret:
//    mchId: 1575431351
//    mchSecret:
//
//management:
//  security:
//    enabled: false
//  health:
//    elasticsearch:
//      enabled: false
//    rabbit:
//      enabled: false
//server:
//  dbIp:
//  mysqlIp: $\{server.dbIp}
//  mysqlWriteIp: $\{server.mysqlIp:dbIp}
//  mysqlReadIp: $\{server.mysqlIp:dbIp}
//  undertow:
//    # 设置IO线程数, 它主要执行非阻塞的任务,它们会负责多个连接, 默认设置每个CPU核心一个线程
//    io-threads: 128
//    # 阻塞任务线程池, 当执行类似servlet请求阻塞IO操作, undertow会从这个线程池中取得线程
//    # 它的值设置取决于系统线程执行任务的阻塞系数，默认值是IO线程数*8
//    worker-threads: 512
//    # 每块buffer的空间大小,越小的空间被利用越充分
//    buffer-size: 512
//    # 是否分配的直接内存(NIO直接分配的堆外内存)
//    direct-buffers: true
//  http2:
//    enabled: true
//
//  use-forward-headers: true
//  servlet:
//    session:
//      cookie:
//        http-only: false
//        max-age: P3D  #3天
//
//
//spring:
//  aop:
//    auto: true
//  http:
//    encoding:
//      charset: UTF-8
//  servlet:
//    multipart:
//      max-file-size: 200MB
//      max-request-size: 200MB
//
//  security:
//    user:
//      name: admin
//      password: admin
//
//  redis:
//    timeout: 3000
//
//security:
//  oauth2:
//    client:
//      client-id:
//      client-secret: clientSecret
//      scope: scope1, scope2, scope3, scope4
//      registered-redirect-uri: http://www.baidu.com
//"""
//
//
//        val http = HttpInvoke()("http://192.168.5.213:8848/nacos/v1/cs/configs")
//        val res = http.doPost("dataId=$dataId&group=$group&tenant=$ns&content=$content&type=$type")
//
//        println(res)
//    }
//
//}
